#include <bits/stdc++.h>
using namespace std;

int main() {
  freopen("badmilk.in", "r", stdin);
  freopen("badmilk.out", "w", stdout);
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int N, M, D, S;

  cin >> N >> M >> D >> S;

  vector<vector<pair<int, int>>> records(N + 1);
  vector<set<int>> people(M + 1), milk(N + 1);
  set<int> ids;

  for (int i = 0; i < D; i++) {
    int p, m, t;

    cin >> p >> m >> t;
    records[p].emplace_back(t, m);
    people[m].insert(p);
  }
  for (int i = 0; i < S; i++) {
    int p, t;

    cin >> p >> t;
    ids.insert(p);
    for (const pair<int, int>& rec : records[p]) {
      if (rec.first < t) {
        milk[p].insert(rec.second);
      }
    }
  }

  int ans = 0;
  for (int i = 1; i <= M; i++) {
    bool succ = true;
    for (int id : ids) {
      if (milk[id].count(i) == 0) {
        succ = false;
        break;
      }
    }
    if (succ) {
      ans = max(ans, (int)people[i].size());
    }
  }
  cout << ans << "\n";
  return 0;
}